rm(list = ls());library(foreign)
install.packages("extrafont", dependencies=TRUE);library(extrafont)
install.packages("RColorBrewer", dependencies=TRUE);library(RColorBrewer)
#setwd("")


a<-read.table("Tw1_4lag_95%.txt");  a1<-read.table("Tw1_4lag_90%.txt")
b<-read.table("Tw2_4lag_95%.txt");b1<-read.table("Tw2_4lag_90%.txt")
c<-read.table("Tw3_4lag_95%.txt");c1<-read.table("Tw3_4lag_90%.txt")
d<-read.table("Tw4_4lag_95%.txt");d1<-read.table("Tw4_4lag_90%.txt")
e<-read.table("TwTOT_4lag_95%.txt");e1<-read.table("TwTOT_4lag_90%.txt")

names(a)[2]<-"US_to_Gov"
names(a)[3]<-"US_to_Gov_Low"
names(a)[4]<-"US_to_Gov_High"
names(a)[5]<-"US_to_Reb"
names(a)[6]<-"US_to_Reb_Low"
names(a)[7]<-"US_to_Reb_High"

names(b)[3]<-"US_to_Gov"
names(b)[4]<-"US_to_Gov_Low"
names(b)[5]<-"US_to_Gov_High"
names(b)[7]<-"US_to_Reb"
names(b)[8]<-"US_to_Reb_Low"
names(b)[9]<-"US_to_Reb_High"

names(c)[3]<-"US_to_Gov"
names(c)[4]<-"US_to_Gov_Low"
names(c)[5]<-"US_to_Gov_High"
names(c)[7]<-"US_to_Reb"
names(c)[8]<-"US_to_Reb_Low"
names(c)[9]<-"US_to_Reb_High"

names(d)[3]<-"US_to_Gov"
names(d)[4]<-"US_to_Gov_Low"
names(d)[5]<-"US_to_Gov_High"
names(d)[7]<-"US_to_Reb"
names(d)[8]<-"US_to_Reb_Low"
names(d)[9]<-"US_to_Reb_High"

names(a1)[2]<-"US_to_Gov"
names(a1)[3]<-"US_to_Gov_Low"
names(a1)[4]<-"US_to_Gov_High"
names(a1)[5]<-"US_to_Reb"
names(a1)[6]<-"US_to_Reb_Low"
names(a1)[7]<-"US_to_Reb_High"

names(b1)[2]<-"US_to_Gov"
names(b1)[3]<-"US_to_Gov_Low"
names(b1)[4]<-"US_to_Gov_High"
names(b1)[5]<-"US_to_Reb"
names(b1)[6]<-"US_to_Reb_Low"
names(b1)[7]<-"US_to_Reb_High"

names(c1)[2]<-"US_to_Gov"
names(c1)[3]<-"US_to_Gov_Low"
names(c1)[4]<-"US_to_Gov_High"
names(c1)[5]<-"US_to_Reb"
names(c1)[6]<-"US_to_Reb_Low"
names(c1)[7]<-"US_to_Reb_High"

names(d1)[2]<-"US_to_Gov"
names(d1)[3]<-"US_to_Gov_Low"
names(d1)[4]<-"US_to_Gov_High"
names(d1)[5]<-"US_to_Reb"
names(d1)[6]<-"US_to_Reb_Low"
names(d1)[7]<-"US_to_Reb_High"


n.ahead<-seq(1,4,by=1);gray<-"#d3d3d3";darkgray<-"#808080"

par(family="Palatino")   
layout(matrix(c(1,2,3,4,5,5), ncol=2,nrow=3, byrow=TRUE), heights=c(3, 3,1))
par(mai=c(0.40,0.40,0.2,0.2),family="Palatino",oma=c(2,2,2,2),mgp=c(2, 0.5, 0),cex.lab=1.2,cex.axis=.8)

plot(n.ahead,a$US_to_Reb[2:5],type="n",main="International Support",lwd=2,col="black",xlab=expression(bold(Time)),ylab=expression(bold(Government)~bold(to)~bold(Rebels)),ylim=c(min(a$US_to_Reb_Low[2:5]),max(a$US_to_Reb_High[2:5])),xlim=c(1,4),xaxt='n')
axis(1,at=c(1,2,3,4), labels=c("1","2","3","4"))
abline(h=0,col="black",lwd=1,lty=3)
points(n.ahead, a$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead, a$US_to_Reb_High[2:5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead, y0=a$US_to_Reb_High[2:5],x1=n.ahead, y1=a$US_to_Reb_Low[2:5],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead, a1$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead, a1$US_to_Reb_High[2:5],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead, y0=a1$US_to_Reb_High[2:5],x1=n.ahead, y1=a1$US_to_Reb_Low[2:5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead, a$US_to_Reb[2:5],lwd=3,pch=19, col= "black",lty=3)

plot(n.ahead,b$US_to_Reb[2:5],type="n",main="Battlefield Success",lwd=2,xlab=expression(bold(Time)),col="black",ylab=expression(bold(Government)~bold(to)~bold(Rebels)),ylim=c(min(b$US_to_Reb_Low[2:5]),max(b$US_to_Reb_High[2:5])),xlim=c(1,4),xaxt='n')
axis(1,at=c(1,2,3,4), labels=c("1","2","3","4"))
abline(h=0,col="black",lwd=1,lty=3)
points(n.ahead, b$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead, b$US_to_Reb_High[2:5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead, y0=b$US_to_Reb_High[2:5],x1=n.ahead, y1=b$US_to_Reb_Low[2:5],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead, b1$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead, b1$US_to_Reb_High[2:5],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead, y0=b1$US_to_Reb_High[2:5],x1=n.ahead, y1=b1$US_to_Reb_Low[2:5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead, b$US_to_Reb[2:5],lwd=3,pch=19, col= "black",lty=3)

plot(n.ahead,c$US_to_Reb[2:5],type="n",main="Clarify Aims",lwd=2,xlab=expression(bold(Time)),col="black",ylab=expression(bold(Government)~bold(to)~bold(Rebels)),ylim=c(min(c$US_to_Reb_Low),max(c$US_to_Reb_High)),xlim=c(1,4),xaxt='n')
axis(1,at=c(1,2,3,4), labels=c("1","2","3","4"))
abline(h=0,col="black",lwd=1,lty=3)

points(n.ahead, c$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead, c$US_to_Reb_High[2:5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead, y0=c$US_to_Reb_High[2:5],x1=n.ahead, y1=c$US_to_Reb_Low[2:5],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead, c1$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead, c1$US_to_Reb_High[2:5],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead, y0=c1$US_to_Reb_High[2:5],x1=n.ahead, y1=c1$US_to_Reb_Low[2:5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead, c$US_to_Reb[2:5],lwd=3,pch=19, col= "black",lty=3)

plot(n.ahead,d$US_to_Reb[2:5],type="n",main="Publicize Atrocities",lwd=2,xlab=expression(bold(Time)),col="black",ylab=expression(bold(Government)~bold(to)~bold(Rebels)),ylim=c(min(d$US_to_Reb_Low),max(d$US_to_Reb_High)),xlim=c(1,4),xaxt='n')
axis(1,at=c(1,2,3,4), labels=c("1","2","3","4"))
abline(h=0,col="black",lwd=1,lty=3)

points(n.ahead, d$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead, d$US_to_Reb_High[2:5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead, y0=d$US_to_Reb_High[2:5],x1=n.ahead, y1=d$US_to_Reb_Low[2:5],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead, d1$US_to_Reb_Low[2:5],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead, d1$US_to_Reb_High[2:5],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead, y0=d1$US_to_Reb_High[2:5],x1=n.ahead, y1=d1$US_to_Reb_Low[2:5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead, d$US_to_Reb[2:5],lwd=3,pch=19, col= "black",lty=3)

par(mai=c(0,0,0,0),family="Palatino")
plot.new()
legend(x="center",title="",horiz=TRUE,legend=c("IRF","95% C.I.","90% C.I."),box.col="gray", col=c("black", darkgray, gray),pch=c(19,17))
